package com.sevenGroup.pawnshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sevenGroup.pawnshop.controller.form.WarehouseStoreForm;
import com.sevenGroup.pawnshop.controller.form.WarehouseStoreForm1;
import com.sevenGroup.pawnshop.exception.sevenGroupException;
import com.sevenGroup.pawnshop.model.WarehouseStore;
import com.sevenGroup.pawnshop.dao.WarehouseStoreDao;
import com.sevenGroup.pawnshop.service.WarehouseStoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sevenGroup
 * @since 2022-02-16
 */
@Service
public class WarehouseStoreServiceImpl extends ServiceImpl<WarehouseStoreDao, WarehouseStore> implements WarehouseStoreService {

    @Resource
    private WarehouseStoreDao warehouseStoreDao;

    @Override
    public void delWarehouseByStoreId(WarehouseStoreForm warehouseStoreForm) throws sevenGroupException {
        if(warehouseStoreForm==null){
            throw new sevenGroupException(40001,"参数为空");
        }
        QueryWrapper<WarehouseStore> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",warehouseStoreForm.getStoreId());
        wrapper.eq("warehouse_id",warehouseStoreForm.getWarehouseId());
        warehouseStoreDao.delete(wrapper);
    }

    @Override
    public void delWarehouseByList(WarehouseStoreForm1 warehouseStoreForm1) throws sevenGroupException {
        if(warehouseStoreForm1==null){
            throw new sevenGroupException(40001,"参数为空");
        }
        QueryWrapper<WarehouseStore> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",warehouseStoreForm1.getStoreId());
        wrapper.in("warehouse_id",warehouseStoreForm1.getWarehouseIds());
        warehouseStoreDao.delete(wrapper);
    }

}
